class BetsController < ApplicationController
  
  def index
    unless params[:serie].blank?
      @matches = Match.all_from_serie(params[:serie])
    else
      @matches = Match.all_by_serie
    end
  end

  def new
  end

  def create
    bets = params[:bet]
    bets.keys.each do |bet|
      b = Bet.first(:conditions => {:user_id => @user.id, :match_id => bet})
      b ||= Bet.new( { :user_id => @user.id, :match_id => bet } )
      b.local_goals = bets[bet][:local_goals]
      b.visitor_goals = bets[bet][:visitor_goals]
      b.save
    end if bets
    if params[:steps]
      redirect_to step_two_steps_url
    else
      redirect_to bets_url(:serie => params[:serie])
    end
  end

end
